import vtkmodules.all as vtk
from enum import Enum


class WidgetState(Enum):
    VTKIS_START = 0
    VTKIS_ROTATE = 1
    VTKIS_PAN = 2
    VTKIS_SPIN = 3
    VTKIS_DOLLY = 4
    VTKIS_ZOOM = 5
    VTKIS_USCALE = 6
    VTKIS_TIMER = 7
    VTKIS_FORWARDFLY = 8
    VTKIS_REVERSEFLY = 9
    VTKIS_TWO_POINTER = 10


class ITrackballCamera(vtk.vtkInteractorStyleTrackballCamera):

    def signal_mouse_wheel(self, delta_x, delta_y):

        pass

    def signal_mouse_move(self, x, y, is_shift_key, is_ctrl_key):
        state = self.GetState()
        if is_ctrl_key:
            if state != WidgetState.VTKIS_PAN:
                self.StartPan()
            self.FindPokedRenderer(x, y)
            self.Pan()
        else:
            if state != WidgetState.VTKIS_ROTATE:
                self.StartPan()
            self.FindPokedRenderer(x, y)
            self.Rotate()
        # _state = self.GetState()
        # match _state:
        #     case 1:
        #         self.FindPokedRenderer(x, y)
        #         self.Rotate()
        #     case 2:
        #         self.FindPokedRenderer(x, y)
        #         self.Pan()

    def signal_left_button_press(self, x, y, is_shift_key, is_ctrl_key):
        self.FindPokedRenderer(x, y)
        if self.GetCurrentRenderer() is None:
            return
        inter = self.GetInteractor()
        if inter is None:
            return
        if is_shift_key:
            if is_ctrl_key:
                self.StartDolly()
            else:
                self.StartPan()
        else:
            if is_ctrl_key:
                self.StartPan()
            else:
                self.StartRotate()

    # define VTKIS_ROTATE 1
    # define VTKIS_PAN 2
    # define VTKIS_SPIN 3
    # define VTKIS_DOLLY 4
    # define VTKIS_ZOOM 5
    def signal_left_button_release(self):
        state = self.GetState()
        match state:
            case 1:
                self.EndRotate()
            case 2:
                self.EndPan()
            case 3:
                self.EndSpin()
            case 4:
                self.EndDolly()
            case 5:
                self.EndZoom()
        # 释放
        if self.GetInteractor() is not None:
            self.ReleaseFocus()
